package com.example.androidproject.utils;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Build;
import android.os.Handler;
import android.os.Looper;
import android.os.Message;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Toast;

import androidx.annotation.NonNull;

import okhttp3.Response;

public class GlobalFunction {
    private static final String TAG = "GGSTUDY";

    /**
     * 隐藏状态栏
     */
    public static void hideStatusBar(Activity activity) {
        if (activity == null) return;
        Window window = activity.getWindow();
        if (window == null) return;
        window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                WindowManager.LayoutParams.FLAG_FULLSCREEN);
        window.getDecorView()
                .setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN | View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
        WindowManager.LayoutParams lp = window.getAttributes();
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
            lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
        }
        window.setAttributes(lp);
    }


//    /**
//     * // 处理 提示框的隐藏
//     */
//    @SuppressLint("HandlerLeak")
//    public static final Handler dialogGONEHandler = new Handler(Looper.getMainLooper()) {
//        @Override
//        public void handleMessage(@NonNull Message msg) {
//            super.handleMessage(msg);
//            GlobalVariable.ll_contentLoding.setVisibility(View.GONE);
//        }
//    };
//    /**
//     * // 处理 提示框的显示
//     */
//    @SuppressLint("HandlerLeak")
//    public static final Handler dialogVisibilityHandler = new Handler(Looper.getMainLooper()) {
//        @Override
//        public void handleMessage(@NonNull Message msg) {
//            super.handleMessage(msg);
//            GlobalVariable.ll_contentLoding.setVisibility(View.VISIBLE);
//        }
//    };

//    /**
//     * // 网络断开了将dialog布局隐藏
//     */
//    public static void netWorkDisconnection_hideDialog(Context mContext, Response response) {
//        Looper.prepare();
//        Log.d(TAG, "onResponse: 请求失败->" + response.code());
//        Toast.makeText(mContext, "请求失败", Toast.LENGTH_SHORT).show();
//        GlobalFunction.dialogGONEHandler.sendMessage(new Message());
//        Looper.loop();
//    }
//    public static void netWorkDisconnection_hideDialog(Context mContext, retrofit2.Response response) {
//        Looper.prepare();
//        Log.d(TAG, "onResponse: 请求失败->" + response.code());
//        Toast.makeText(mContext, "请求失败", Toast.LENGTH_SHORT).show();
//        GlobalFunction.dialogGONEHandler.sendMessage(new Message());
//        Looper.loop();
//    }
}
